package com.caishi.lkx.exam.ienum;

import java.util.Arrays;

public interface BaseEnum<T> {
    T getCode();

    static <E extends Enum<E> & BaseEnum<T>, T> E fromCode(Class<E> enumClass, T code) {
        return Arrays.stream(enumClass.getEnumConstants())
                .filter(e -> e.getCode().equals(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unknown enum code: " + code));
    }
}